from langgraph.graph import StateGraph,START,END
from IPython.display import Image,display


builder = StateGraph(dict)

def addition(state):
    print(state)
    return {"x":state["x"]+1}

def substraction(state):
    print(state)
    return {"y":state["x"]-2}

builder.add_node("addition",addition)
builder.add_node("substraction",substraction)

builder.add_edge(START,"addition")
builder.add_edge("addition","substraction")
builder.add_edge("substraction",END)

graph = builder.compile()
res = graph.invoke({"x":10})
print(res)

display(Image(graph.get_graph(xray=True).draw_mermaid_png()))